<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.shsh.safemanage.util.MessageUtil"%>
<%@page import="com.shsh.safemanage.model.PostCheck"%>
<%@page import="com.shsh.safemanage.model.Equipment"%>
<%@page import="com.shsh.safemanage.model.Department1"%>
<%@page import="java.util.Set"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.dao.UserDao"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.model.User"%>

<div class="hider" id="hider">
	<span>&nbsp;</span>
</div>
<div class="position">
	<img src="images/position2.jpg" style="padding: 7px 9px; float: left;" />当前位置：中国石化安全问题管理平台 &gt;&gt; 注册
</div>
<%
User registerUser = (User) session.getAttribute(Constants.SESSION_REGISTER_USER);
UserDao userDao = DaoCreator.createUserDao();
%>
<div class="tt">员工初始注册</div>
<div class="content">
	<table align="center" border="1" width="700" cellpadding="0"
		cellspacing="0">
		<tr>
			<td class="td1" height="35">
				<span style="margin-left: 20px" class="span1">姓 名：</span>
				<input type="text" name="name" id="name" size="15" value="<%=(registerUser == null)? "":registerUser.getName() %>" />
				<span style="margin-left: 20px" class="span1">工 号：</span>
				<input type="text" name="jobNum" id="jobNum" size="20" value="<%=(registerUser == null)? "":registerUser.getJobNum() %>" />
				<span style="margin-left: 10px">输入姓名工号点击注册</span>
				<input type="button" style="margin-left: 4px" value="注册" onclick="refreshUser()" />
			</td>
		</tr>
		<%
		if (registerUser == null || registerUser.getDepartmentType() == Constants.DEPARTMENT_TYPE_SHIYEBU) {
		%>
		<tr>
			<td class="td1" height="35">
				<span style="margin-left: 20px" class="span1">作业部（业务中心）：</span>
				<%
				if (registerUser == null) {
				%>
				<a href="#" onclick="$.dialog.alert('<%=MessageUtil.getMessage(Constants.ERROR_KEY_NULL_REGISTER_USER)%>')">选择</a>
				<%
				} else {
				%>
				<span style="color: black;"><%=registerUser.getDepartment1Name()%>-<%=registerUser.getDepartment2Name()%>-<%=registerUser.getDepartment3Name() %></span>
				<a href="#" onclick="openDialogPage('choose_department123.jsp?departType=2&depart1ID=<%=registerUser.getDepartment1ID()%>&depart2ID=<%=registerUser.getDepartment2ID()%>', 'depart123Dialog', '选择所属部门')">修改</a>
				<%
				}
				%>
				<br />
				<span style="margin-left: 20px" class="span1">职务（岗位）：</span>
				<%
				if (registerUser != null) {
				%>
				<span style="color: black; margin-left: 5px"><%=(registerUser.getJobPost1Name()==null)? "":registerUser.getJobPost1Name()%></span>
				<span style="color: black; margin-left: 5px"><%=(registerUser.getJobPost2Name()==null)? "":registerUser.getJobPost2Name()%></span>
				<span style="color: black; margin-left: 5px"><%=(registerUser.getJobPost3Name()==null)? "":registerUser.getJobPost3Name()%></span>
				<%
				}
				%>
				<%
				if (registerUser == null) {
				%>
				<a href="#" onclick="$.dialog.alert('<%=MessageUtil.getMessage(Constants.ERROR_KEY_NULL_REGISTER_USER)%>')">选择添加</a>
				<%
				} else {
				%>
				<a href="#" onclick="openDialogPage('choose_post.jsp?departType=2&depart1ID=<%=registerUser.getDepartment1ID()%>&depart2ID=<%=registerUser.getDepartment2ID()%>', 'postDialog', '选择岗位')">选择添加</a>
				<%
				}
				%>
				<br />
				<span style="margin-left: 20px" class="span1">对口装置（灌区、专业、站）：</span>
				<a href="#" onclick="openDialogPage('choose_equipment2.jsp', 'equip2ListDialog', '选择添加对口装置（灌区、专业、站）')">选择添加</a>
				<%
				Set<Equipment> mappingEquip2Set = (Set<Equipment>) session.getAttribute(Constants.SESSION_MAPPING_EQUIPMENT2);
				if (mappingEquip2Set != null && mappingEquip2Set.size() > 0) {
				%>
				<br />
				<span style="margin-left: 30px">
				<%
					for (Equipment equip2 : mappingEquip2Set) {
				%>
				<span style="color: black; margin-left: 5px"><%=equip2.getEquipName()%><%=(equip2.isEquipmentManager())? "(装置长)":""%></span> <a href="">删除</a>
				<%
					}
				%>
				</span>
				<%
				}
				%>
			</td>
		</tr>
		<%
		}
		%>
		<%
		if (registerUser == null || registerUser.getDepartmentType() == Constants.DEPARTMENT_TYPE_JIGUAN) {
		%>
		<tr>
			<td class="td1" height="35">
				<span style="margin-left: 20px" class="span1">公司机关：</span>
				<%
				if (registerUser == null) {
				%>
				<a href="#" onclick="$.dialog.alert('<%=MessageUtil.getMessage(Constants.ERROR_KEY_NULL_REGISTER_USER)%>')">选择</a>
				<%
				} else {
				%>
				<span style="color: black;"><%=registerUser.getDepartment1Name()%>-<%=registerUser.getDepartment2Name()%>-<%=registerUser.getDepartment3Name() %></span>
				<a href="#" onclick="openDialogPage('choose_department123.jsp?departType=1&depart1ID=<%=registerUser.getDepartment1ID()%>&depart2ID=<%=registerUser.getDepartment2ID()%>', 'depart123Dialog', '选择所属部门')">修改</a>
				<%
				}
				%>
				<br />
				<span style="margin-left: 20px" class="span1">职务（岗位）：</span>
				<%
				if (registerUser != null) {
				%>
				<span style="color: black;"><%=(registerUser.getJobPost1Name()==null)? "":registerUser.getJobPost1Name()%></span>
				<span style="color: black;"><%=(registerUser.getJobPost2Name()==null)? "":registerUser.getJobPost2Name()%></span>
				<span style="color: black;"><%=(registerUser.getJobPost3Name()==null)? "":registerUser.getJobPost3Name()%></span>
				<%
				}
				%>
				<%
				if (registerUser == null) {
				%>
				<a href="#" onclick="$.dialog.alert('<%=MessageUtil.getMessage(Constants.ERROR_KEY_NULL_REGISTER_USER)%>')">选择添加</a>
				<%
				} else {
				%>
				<a href="#" onclick="openDialogPage('choose_post.jsp?departType=1&depart1ID=<%=registerUser.getDepartment1ID()%>&depart2ID=<%=registerUser.getDepartment2ID()%>', 'postDialog', '选择岗位')">选择添加</a>
				<%
				}
				%>
				<br />
				<span style="margin-left: 20px" class="span1">对口作业部：</span>
				<a href="#" onclick="openDialogPage('choose_department1.jsp', 'departListDialog', '选择添加对口作业部')">选择添加</a>
				<%
				Set<Department1> mappingDepart1Set = (Set<Department1>) session.getAttribute(Constants.SESSION_MAPPING_SHIYEBU);
				if (mappingDepart1Set != null && mappingDepart1Set.size() > 0) {
				%>
				<br />
				<span style="margin-left: 30px">
				<%
					for (Department1 depart1 : mappingDepart1Set) {
				%>
				<span style="color: black; margin-left: 5px"><%=depart1.getDepartmentName()%></span> <a href="">删除</a>
				<%
					}
				%>
				</span>
				<%
				}
				%>
				<br />
				<span style="margin-left: 20px" class="span1">对口装置（灌区、专业、站）：</span>
				<a href="#" onclick="openDialogPage('choose_equipment1.jsp', 'equipListDialog', '选择添加对口装置（灌区、专业、站）')">选择添加</a>
				<%
				Set<Equipment> mappingEquip1Set = (Set<Equipment>) session.getAttribute(Constants.SESSION_MAPPING_EQUIPMENT);
				if (mappingEquip1Set != null && mappingEquip1Set.size() > 0) {
				%>
				<br />
				<span style="margin-left: 30px">
				<%
					for (Equipment equip1 : mappingEquip1Set) {
				%>
				<span style="color: black; margin-left: 5px"><%=equip1.getEquipName()%><%=(equip1.isEquipmentManager())? "(装置长)":"" %></span> <a href="">删除</a>
				<%
					}
				%>
				</span>
				<%
				}
				%>
			</td>
		</tr>
		<%
		}
		%>
		<tr>
			<td class="td1" height="35">
				<span style="margin-left: 20px" class="span1">管理组：</span>
				<%
				if (registerUser != null ) {
				%>
				<span style="color: black;"><%=(registerUser.getManageGroupName()==null)? "":registerUser.getManageGroupName()%></span>
				<%
				}
				%>
				<%
				if (registerUser == null) {
				%>
				<a href="#" onclick="$.dialog.alert('<%=MessageUtil.getMessage(Constants.ERROR_KEY_NULL_REGISTER_USER)%>')">选择</a>
				<%
				} else {
				%>
				<a href="#" onclick="openDialogPage('choose_manage_group.jsp', 'manageGroupDialog', '选择所属管理组')">选择</a>
				<%
				}
				%>
				<br />
				<%
				if (registerUser == null || userDao.getUserTitleLevel(registerUser.getJobTitleID()) < Constants.TITLE_LEVEL_CHU) {
				%>
				<span style="margin-left: 20px" class="span1">选择岗检栏目：</span>
				<a href="#" onclick="openDialogPage('choose_postcheck.jsp', 'postcheckListDialog', '选择添加关注岗检')">选择添加</a>
				<%
				Set<PostCheck> postCheckSet = (Set<PostCheck>) session.getAttribute(Constants.SESSION_MAPPING_POSTCHECK_SET);
				if (postCheckSet != null && postCheckSet.size() > 0) {
				%>
				<br />
				<span style="margin-left: 30px">
				<%
					for (PostCheck postcheck : postCheckSet) {
				%>
				<span style="color: black; margin-left: 5px"><%=postcheck.getCheckName()%></span> <a href="">删除</a>
				<%
					}
				%>
				</span>
				<%
				}
				%>
				<%
				}
				%>
			</td>
		</tr>
		<tr>
			<td class="td1" height="35">
				<span style="margin-left: 20px" class="span1">密 码：</span>
				<input type="text" name="password" id="password" size="15" />
				<span style="margin-left: 20px" class="span1">确认密码：</span>
				<input type="text" name="confirmPassword" id="confirmPassword" size="15" />
				<span style="margin-left: 5px">（可不填写）</span>
			</td>
		</tr>
		<tr>
			<td class="td1" height="500" align="center">
			<%
			if (registerUser == null || registerUser.isRegistered()) {
			%>
				<input type="button" value="确认信息并注册" disabled="disabled" />
			<%
			} else {
			%>
				<input type="button" value="确认信息并注册" onclick="register()" />
			<%
			}
			%>
			</td>
		</tr>
	</table>
</div>

<script type="text/javascript">
function register() {
	openWaitingDialog('waitingDialog');
	$.ajax({
		type:'post',
		url:'register_process.jsp',
		data:{
			password: getElementValueByID('password'),
			confirmPassword: getElementValueByID('confirmPassword')
		},
		success:function(data,state,xmlhttp){
			var obj = null;
			try {
				obj = eval('(' + data + ')');
			} catch (e) {
			}
			if (typeof(obj.isSuccess) != 'undefined') {
				closeWaitingDialog('waitingDialog');
				if (obj.isSuccess == 'true') {
					$.dialog('注册成功！', function() { loadPageSection('/safe_manage/login.jsp', 'mainContentDiv'); });
				} else {
					$.dialog.alert(obj.error);
				}
			}
		}
	});
}
</script>
